// pages/pages-list/huizhan-details2/huizhan-details2.js
import api from '../../../utils/api/api'
import tool from "../../../utils/publics/tool"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jkl_detail: {}, // 详情
    isUseShare: true, // 局部分享
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options,"options");
    let scene = '';
    if( options.scene){
       scene = options.scene.split('_')[1]
    }
    this.setData({
      id: options.id || scene 
    })
    this.getData();
  },
  // 获取数据
  getData() {
    tool.loading("", "loading")
    api.jkl_detailt({
      id: this.data.id
    }).then(res => {
      tool.loading_h()
      let {
        code,
        data,
        msg
      } = res;
      this.setData({
        jkl_detail: data
      })
    })
  },
  // 跳转
  skip(e) {
    let type = e.currentTarget.dataset.type;
    let jkl_detail = this.data.jkl_detail;
    if(type==1){
      if (jkl_detail.join_detail.pay_status == 1) { // 支付状态 0待支付 1已支付 -1已取消   
        tool.jump_nav(`/pages/pages-list/success2/success2?id=${jkl_detail.id}`)
      }else{
        tool.jump_nav(`/pages/pages-list/enter/enter?id=${this.data.id}`)
      }
    }else if(type==2){    // 取消订单
      api.jkl_cancel_order({id:jkl_detail.join_detail.id}).then(res=>{
        let {code,data,msg} =res;
        tool.alert("取消成功",1)
        if(code==1){
          this.getData();
        }
      })
    }else{     // 支付
       api.jkl_order_pay({id:jkl_detail.join_detail.id}).then(res=>{
        let {code,data,msg} =res;
        if(code==1){
          let this_ = this;
          wx.requestPayment({
            ...data,
            success(res) {
              tool.alert("报名成功", 1);
             tool.jump_rel(`/pages/pages-list/success2/success2?id=${jkl_detail.id}`)
            },
            fail(res){

            }
          })
        }
      })
    }
   
   
  },
  // 授权手机号回调
  getPhoneCallback(e) {
    if(e.target.dataset.type !=1)return;
    let jkl_detail = this.data.jkl_detail;
      if (jkl_detail.join_detail.pay_status == 1) { // 支付状态 0待支付 1已支付 -1已取消   
        tool.jump_rel(`/pages/pages-list/success2/success2?id=${jkl_detail.id}`)
      }else{
        tool.jump_nav(`/pages/pages-list/enter/enter?id=${this.data.id}`)
      }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    let nickname = getApp().store.$state.userInfo.nickname || '';
    let title = `${nickname}邀请您一起参加金卡纳魔王挑战`;
    let id = this.data.id;
    return {
      title,
      path: `/pages/pages-list/huizhan-details2/huizhan-details2?id=${id}}`,
      imageUrl: `https://img.vrupup.com/web/rq/ait/images/share3.png`,
      query: '分享',
    }
  }
})